<div class="referbox">
<h4 class="dis-cons-title">商品咨询</h4>
      <div class="goods-discus-title">
      <p class="flt consult-tips">对商品有什么问题，请在这里咨询吧</p><a href="#write_ask" class="orangebtn allnum consult-ask"><!--<i class="has-icon"> <img  style="margin:0"src='<{$env.app.res_url}>/bundle/pencil.gif' /></i>--><span>我要咨询</span></a>
    </div>
      <div class="consult">
    <{if $gask_type}>
	<ul class="consult-list clearfix">
	 <li class="active active_type"><{t}>全部咨询<{/t}><span>(<em><{$comment.askCount|default:'0'}></em>条)</span>
	<{foreach from=$gask_type item="gask_type1"}>
    <li class="active_type"><{$gask_type1.name}><span>(<em><{$gask_type1.total}></em>条)</span>
    <input type="hidden" value='<{$gask_type1.type_id}>'>
    </li>
    <{/foreach}>
	</ul>
	<{/if}>
    <div class="goods-discus-title bulelink"> <{t}>共<{/t}><span id="product_askcount" class="value-color"><{$comment.askCount|default:'0'}></span><{t}>人咨询<{/t}>&nbsp;&nbsp;<span class="all_link"><a href="#ask_all_info" class="allnum " ><{t}>查看所有咨询<{/t}></a> </span></div>
<div class="consult-content">
	<a name="ask_all_info"></a>
    <div class="consult-panel" id="consult_content"><{include file="site/product/consult_content.html" app="b2c"}></div>
</div>
</div>
<div style="display:none" class="displaydiv">
 <a name="write_ask"></a>
 <div class="review-box">
  <form class="addcomment" method="post" action='<{link app=b2c ctl=site_comment act=toComment arg0=$goods.goods_id arg1=ask}>' onSubmit='return checkFormReqs(event);'>
      <h4 class="review-title"><{t}>发表咨询<{/t}></h4>
      <div class="consult-cont">
      <div class="division clearfix">
      	<div <{if $ask_status}>class="leftbox"<{else}>class="leftbox askfloat message-login"<{/if}>>
        <ul>
		<{if $gask_type}>
          <li><{t}>咨询类型 : <{/t}>
            <{foreach from=$gask_type item="gask_type"}>
              <{$gask_type.name}><input type="radio" <{if $gask_type.type_id == 1}>checked="checked"<{/if}> value="<{$gask_type.type_id}>" name="gask_type" />
              <{/foreach}>
          </li>
		  <{/if}>

        <{if $ask_status}>
             <li>
             <{assign var="placeholder" value="欢迎发表咨询（最多1000字）"}>
        <{else}>
             <li class="ask_float message-login">
             <{assign var="disb" value="true"}>
             <p><{$ask_message}></p>
        <{/if}>
           <{input type="textarea" class="inputstyle font12px db mb5" placeholder=$placeholder disabled=$disb  vtype="sendcomments" rows="5" name="comment" style="width:96%" id="send_comment"}>
              <div class="infotips textright" ><span class="font-orange" id="num">0</span>/1000</div>
              <script>
	                window.addEvent('domready',function(){
                      $LAB.wait(function(){
	                    validatorMap['sendcomments'] = ['<{t}>字数应该在1-1000个字之内<{/t}>', function(element, v) {
	                        if ($(element).get('value') == '' || $(element).get('value').length < 1 || $(element).get('value').length > 1000){
	                            return false;
	                        }
	                        else
	                            return true;
	                    }];
	                });

                    $('send_comment').addEvent('keyup',function(e){
                        var num = $('send_comment').value.length;
                        if($('send_comment').value.length == 0){
                            $('num').innerHTML= 0;
                            }else{
                            $('num').innerHTML= num;
                            }
                        if(parseInt($('num').innerHTML) >1000){
                            $('send_comment').value = $('send_comment').value.substr(0,1000);
                            $('num').innerHTML= 1000;
                            exit;
                        }
                    });
                    });
	            </script>
          </li>
          <{if $login eq "nologin"}>
          <li>
            <{t}>联系方式：<{/t}>
            <{input type="text" vtype=required class="inputstyle"  disabled=$disb size=20 name="contact"}><span class="infotips"><{t}>(可以是电话、email、qq等)<{/t}></span>
          </li>
          <{/if}>
          <{if $askshow == "on"}>
         <!--
           <li>
            <{t}>验证码：<{/t}>
            <{input type="text" vtype=required size="4" maxlength="4" name="askverifyCode"}>&nbsp;<img src="<{link app="b2c" ctl="site_comment" act="gen_askvcode" arg0=$smarty.now}>" align="absmiddle" id="askimgVerifyCode"/><a href="javascript:changeimg('askimgVerifyCode','ask')">&nbsp;<{t}>看不清楚?换个图片<{/t}></a>
          </li> -->
           <li><{t}>验证码:  <{/t}><{input type="text" vtype=required disabled=$disb size="4" maxlength="4" class="showdisaskvcode" name="askverifyCode"}>&nbsp;<img id="askimgVerifyCode" style="display:none" codesrc="<{link app="b2c" ctl="site_comment" act="gen_askvcode"}>"/><a onclick="javascript:changeimg('askimgVerifyCode','ask');" class="no-unl">&nbsp;<{t}>点击更换新图片<{/t}></a><span></span></li>
          <{/if}>
          <{if $login != "nologin"}>
          <li>
            <{t}>匿名发表:<{/t}>
            <input type="checkbox" name="hidden_name" value="YES"/>
          </li>
          <{/if}>

          <li>
          <{if ($ask_status == '') && ($login == 'nologin' || $ask_message != '')}>
                <button class="btn" type="button" disabled><span><span><{t}>提交咨询<{ $base_setting.comment.display.discuss}><{/t}></span></span></button>

          <{else}>
                <button class="btn" data-ajax-config="{update:$$('[data-sync-type=goodsconsult]')[0], onComplete:function(){if((/text\/jcmd/).test(this.getHeader('Content-type'))) {return;}Message.success('<{$submit_msg}>');$$('.consult-ask').getParent('.pdtdetail').getElement('.displaydiv').show();$$('[data-tab-type=goodsconsult]')[0]&&$$('[data-tab-type=goodsconsult]')[0].getElement('em').set('html',$('product_askcount').get('html'));}}" rel="_request" type="submit" id="product-consult-submitBtn"><span><span><{t}>提交咨询<{ $base_setting.comment.display.discuss}><{/t}></span></span></button>
          <{/if}>

          </li>
        </ul>
        </div>
         <div class="rightbox"><p><{$comment.submit_comment_notice.ask}></p>
</div></div>
<div class="clear"></div>
      </div>
      </div>
    </form>
    </div>

      </div>

<!-- 回复 -->
<div id="ask_html" class="<{if $discuss_status}>repay-box<{else}>repay-box discussfloat message-login<{/if}>" style="display:none;">
    <div class="lt"></div>
    <div class="rt"></div>
    <div class="lb"></div>
    <div class="rb"></div>
    <div class="arrw"></div>
    <form method="post" onsubmit='checkFormReqs(event);'>
      <div class="review-textarea">
        <ul>
          <li class="message-login" id="repay_textarea">
          <{if $ask_status}>
          <{assign var="placeholder" value="欢迎咨询（最多1000字）"}>
          <{else}>
          <{assign var="disbs" value="true"}>
          <p><{$ask_message}></p>
          <{/if}>
          <{input type="textarea" class="inputstyle font12px db mb5" placeholder=$placeholder  disabled=$disbs vtype="sendcomments" rows="5" name="comment" style="width:98%"}>
          <div class="infotips" align="right"><span class="price1">0</span>/1000</div>
          </li>
          <{if $login eq "nologin"}>
          <li><{t}>联系方式:<{/t}><{input type="text" class="inputstyle" required="true" size=20 name="contact"}><span class="infotips"><{t}>(可以是电话、email、qq等)<{/t}></span>
          </li>
          <{else}>
          <li><input type="text" name="" style="display:none" />
          <input type="checkbox" name="hidden_name" value="YES"/>
          匿名发表</li>
          <{/if}>
          <{if $askshow == "on"}>
          <li><{t}>验证码：<{/t}><{input type="text" style=" width:70px" disabled=$disbs vtype=required size="4" maxlength="4" class="showvcode showdisaskvcode" onchange="replyVcodeCheck(this)" name="replyverifyCode"}>&nbsp;<img style="display:none" codesrc="<{link app="b2c" ctl="site_comment" act="gen_replyvcode"}>"/><a href="javascript:void(0);" onclick="changereplyimg(this);"class="link-blue">&nbsp;<{t}>点击更换新图片<{/t}></a><span></span></li>
          <{/if}>
          <li style="padding-left:0">
          <{if ($ask_status == '') && ($login == 'nologin' || $ask_message != '')}>
              <button class="btn" type="button" disabled><span><span> <{t}>提 交<{/t}></span></span> </button>
          <{else}>
              <button id="cart-coupon-submitBtn" class="btn" type="submit" rel="_request" data-ajax-config="{update:$$('[data-sync-type=goodsconsult]')[0], onComplete:function(){if((/text\/jcmd/).test(this.getHeader('Content-type'))) {return;}Message.success('发表成功');$$('.consult-ask').getParent('.pdtdetail').getElement('.displaydiv').show();}}"> <span><span> <{t}>提 交<{/t}></span></span> </button>
          <{/if}>
          <span style="cursor:pointer" class="link-blue" onclick="cancle();">取消回复</span>
          </li>
        </ul>
      </div>
    </form>
  </div>

<script>

(function(){
    $$('.consult-panel').addEvent('click',function(e){
                //this.hide();
        if(!$(e.target).hasClass('repay_span'))return;
        if($('new_repay_box'))
        $('new_repay_box').destroy();
        var replay_div = '';
        var replay_form = '';
        var textValue = '';
        var repayTextarea = '';

        if($(e.target).hasClass('ask-btn')){
          replay_div = $('ask_html').clone().show();
          textValue = "欢迎咨询（最多1000字）";
        }
        else if($(e.target).hasClass('comment-btn')){
          replay_div = $('comment_html').clone().show();
          textValue = "欢迎发表评论（最多1000字）";

        }
        replay_form = replay_div.getElement('form');
        new Request({
          url:'<{link app="b2c" ctl="site_comment" act="reply_link"}>',
          onComplete:function(response){
            replay_form.action = response;
            var el =replay_div.getElement('textarea') ;
            if(!('placeholder' in document.createElement('input'))) {
              el.setStyles({'fontSize':'12px','color':'#999'});
              el.value = textValue;
              el.addEvent('focus',function(e){
                if($(e.target).value  === $(e.target).get('placeholder')){
                  el.setStyle('color','#000');
                  $(e.target).value = '';
                }
              });
            };

            el.addEvent('keyup',function(e){
              var limitNum = 1000;
              var _parent = $('new_repay_box');
              if($(e.target).value.length > limitNum) $(e.target).value = $(e.target).value.substring(0,limitNum);
              _parent.getElement('.price1').set('text',$(e.target).value.length);
            });

          }
        }).post('comment_id='+$(e.target).id);
        replay_div.setProperty('id','new_repay_box');
        replay_div.inject($(e.target).getParent('div'),'after');
      });

    $$('.showdisaskvcode').addEvent('focus',function(){
        if (this.retrieve('showdisaskvcode',false)) return;
        var vcodeImg = this.getNext('img');
        vcodeImg.src = vcodeImg.get('codesrc')+'?'+(+new Date());
        vcodeImg.show();
        this.store('showdisaskvcode',true);
    });

	$$('.showdisaskvcode').fireEvent('focus');

    $$('.consult-panel').addEvent('click',function(e){
        if(!$(e.target).hasClass('showvcode'))return;
        if ($(e.target).retrieve('showvcode',false))return;
        var vcodeImg = $(e.target).getNext('img');
        vcodeImg.src = vcodeImg.get('codesrc')+'?'+(+new Date());
        vcodeImg.show();
        $(e.target).store('showvcode',true);
    });

    $$('.consult-ask').addEvent('click',function(e){
        this.getParent('.pdtdetail').getElement('.displaydiv').show();
    });

	$$('.active_type').addEvent('click',function(){
		if(this.hasClass('active')) return ;
		this.removeClass('active_type');
		if($$('.consult-list .active')[0])$$('.consult-list .active')[0].removeClass('active');
		this.addClass('active');
		var type_id = '';
		if(this.getFirst('input')) type_id = this.getFirst('input').value;
		 new Request.HTML({
		  url:'<{link app="b2c" ctl="site_comment" act="ajax_type_ask"}>',
		  update:$('consult_content'),method:'post',
		  data:'goods_id=<{$goods.goods_id}>&type_id='+type_id
	  }).send();
	});

})();
</script>
